package cn.uway.netty.client;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class TcpClientHandler extends ChannelInboundHandlerAdapter {
	
   private  Logger logger = LoggerFactory.getLogger(this.getClass());
	 
   public static String byte2HexString(byte[] array){
	    StringBuffer sb = new StringBuffer();
		for(int i=0;i<array.length;i++){
			String hex = Integer.toHexString(array[i] & 0xFF); 
		     if (hex.length() == 1) { 
		         hex = '0' + hex; 
		     }
		     sb.append(hex);
		}
		return sb.toString();
	}
	
	public void channelRead(ChannelHandlerContext ctx, Object msg)	throws Exception {
		ByteBuf buf = (ByteBuf)msg;
		byte[] dest = new byte[buf.readableBytes()];
		buf.readBytes(dest);
		
		logger.debug("client receive byte to hex:"+byte2HexString(dest) );
		
	}
}
